<template>
  <div>
    <nav-bar :title="title" :isShow="false"></nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="name"
        name="name"
        label="联系人"
        placeholder="联系人"
      />
      <van-field
        v-model="telephone"
        name="telephone"
        label="联系电话"
        placeholder="联系电话"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>

  </div>
</template>

<script>
import NavBar from '@/components/NavBar'
import { addCompanyPerson } from '@/api/service'

export default {
  components: {
    NavBar,
  },
  props: {
    company_id: {
      type: String,
      default: "",
    }
  },
  data() {
    return {
      title: this.$route.meta.title || "",
      name: "",
      telephone: "",
    };
  },
  methods: {
    onSubmit(values) {
      const openid = localStorage.getItem("openid")
           
      values["openid"] = openid
      values["company"] = +this.company_id
      console.log("onSubmit:", values)

      this.addCompanyPerson(values)   //增加
      
    },
    addCompanyPerson(personInfo){
      addCompanyPerson(personInfo).then(res=>{
        console.log(res);
        if(res){
          this.$notify({ type: 'success', message: '保存成功' })
          setTimeout(()=>{
            this.$router.push("/")
          }, 1000)
        }
      }).catch(error=>{
        console.log(error);
      })
    }

  },
  created() {

  },

};
</script>

<style  scoped>

</style>